package scribble;

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;

public class Scribble2 extends Scribble{
//	protected  ScribbleCanvas canvas;
//	protected EventListener listener;
//	protected boolean isApplet = false;
	
	public Scribble2(boolean isApplet){
		super(isApplet);

		getContentPane().add(makeControlPanel(), BorderLayout.SOUTH);

		
	}
	public Scribble2(){
		//invoked as an applet
		this(true);
	}
	
	protected Component makeControlPanel() {
		JPanel controlPanel = new JPanel();
		JButton button = new JButton("Clear");
		controlPanel.add(button);
		button.addActionListener(new ClearButtonListener());
		
		controlPanel.add(new JLabel("Pen Color"));
		JComboBox choice = new JComboBox();
		choice.addItem("black");
		choice.addItem("blue");
		choice.addItem("green");
		choice.addItem("red");
		choice.addItemListener(new ColorChoiceListener());
		controlPanel.add(choice);
		return controlPanel;
	}
	
	
	public static void main(String[] args){
		JFrame frame = new JFrame();
		frame.setTitle("Scribble Pad 2");
		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(new Scribble2 (false), BorderLayout.CENTER);
		frame.addWindowListener(new AppCloser());
		frame.pack();
		frame.setSize(600, 400);
		frame.show();
	}
	
	class ClearButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
			canvas.clearCanvas();
			canvas.repaint();
		}
	}
	
	class ColorChoiceListener implements ItemListener{
		public void itemStateChanged(ItemEvent event){
			if(event.getStateChange() == ItemEvent.SELECTED){
				if("black".equals(event.getItem())){
					canvas.setPenColor(Color.black);
				} else if("blue".equals(event.getItem())){
					canvas.setPenColor(Color.blue);
				
				} else if("green".equals(event.getItem())){
					canvas.setPenColor(Color.green);
				} else if("red".equals(event.getItem())){
						canvas.setPenColor(Color.red);
				}	
			}
			
		}
	}
	
}
